import java.lang.reflect.Array;

class Solution {
    public static void rotateSelf(int[] nums, int k) {
        int left = 0;
        int right = nums.length - 1;
        while (left < right) {
            int tmp = 0;
            tmp = nums[left];
            nums[left] = nums[right];
            nums[right] = tmp;
            left++;
            right--;
        }
    }

    public static void rotate(int[] nums, int k) {
        k = k % nums.length;
        int[] array = new int[k];
        int j = 0;
        for (int i = nums.length - k; i < nums.length; i++) {
            array[j] = nums[i];
            j++;
        }
        for (int i = nums.length - 1; i >= k; i--) {
            nums[i] = nums[i - k];
        }
        System.arraycopy(array, 0, nums, 0, k);
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 3, 4, 5, 6, 7};
        rotate(nums, 3);
        for (int i : nums) {
            System.out.println(i);
        }
    }

    public static int missingNumber(int[] nums) {
        int[] array = new int[nums.length + 1];
        for (int num : nums) {
            Array.setInt(array, num, num);
        }
        for (int i = 0; i < nums.length + 1; i++) {
            if (array[i] != i) {
                return i;
            }
        }
        return 0;
    }

    public static void main1(String[] args) {
        System.out.println(missingNumber(new int[]{0, 1, 3, 4, 5}));
    }
}